package com.xiaoyu.lingdian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.xiaoyu.lingdian.service.CorePointsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoyu.lingdian.core.mybatis.dao.MyBatisDAO;
import com.xiaoyu.lingdian.core.mybatis.page.Page;
import com.xiaoyu.lingdian.core.mybatis.page.PageRequest;
import com.xiaoyu.lingdian.entity.CorePointsOrder;

@Service("corePointsOrderService")
public class CorePointsOrderServiceImpl implements CorePointsOrderService {

	@Autowired
	private MyBatisDAO myBatisDAO;

	@Override
	public boolean insertCorePointsOrder(CorePointsOrder corePointsOrder) {
		myBatisDAO.insert(corePointsOrder);
		return true;
	}

	@Override
	public boolean updateCorePointsOrder(CorePointsOrder corePointsOrder) {
		myBatisDAO.update(corePointsOrder);
		return true;
	}

	@Override
	public boolean deleteCorePointsOrder(CorePointsOrder corePointsOrder) {
		myBatisDAO.delete(corePointsOrder);
		return true;
	}

	@Override
	public CorePointsOrder getCorePointsOrder(CorePointsOrder corePointsOrder) {
		return (CorePointsOrder) myBatisDAO.findForObject(corePointsOrder);
	}

	private static final String FIND_CORE_POINTSORDER_BY_CND = "findCorePointsOrderByCnd";
	private static final String DELETE_CORE_POINTSORDER_BY_CND = "deleteCorePointsOrderByCnd";
	
	@SuppressWarnings("unchecked")
	@Override
	public Page<CorePointsOrder> findCorePointsOrderByCnd(
			String crporGoodsName, String crporUser, int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crporGoodsName", crporGoodsName);
		hashMap.put("crporUser", crporUser);
		return myBatisDAO.findForPage(FIND_CORE_POINTSORDER_BY_CND, new PageRequest(pageNum, pageSize, hashMap));
	}

	@Override
	public boolean deleteCorePointsOrderByCnd(List<String> list) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("list", list);
		myBatisDAO.delete(DELETE_CORE_POINTSORDER_BY_CND, hashMap);
		return true;
	}	

	
}